package com.xiaobai.demo.mapper;

import com.xiaobai.demo.pojo.Diagnostic;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface DiagnosticMapper {

    // 查询所有诊断记录
    @Select("SELECT * FROM diagnosisRecords")
    List<Diagnostic> findAll();

    // 根据 id 查询诊断记录
    @Select("SELECT * FROM diagnosisRecords WHERE id = #{id}")
    Diagnostic findById(@Param("id") Integer id);

    // 根据 userId 查询诊断记录
    @Select("SELECT * FROM diagnosisRecords WHERE userId = #{userId}")
    List<Diagnostic> findByUserId(@Param("userId") Integer userId);

    // 新增诊断记录
    @Insert("INSERT INTO diagnosisRecords(userId, diagnosisTime, diagnosisResult, signalStrength, latency, downloadSpeed, uploadSpeed, diagnosisType, location, deviceModel, networkType, details, createdAt, updatedAt) VALUES(#{userId}, #{diagnosisTime}, #{diagnosisResult}, #{signalStrength}, #{latency}, #{downloadSpeed}, #{uploadSpeed}, #{diagnosisType}, #{location}, #{deviceModel}, #{networkType}, #{details}, #{createdAt}, #{updatedAt})")
    int save(Diagnostic diagnostic);

    // 更新诊断记录
    @Update("UPDATE diagnosisRecords SET userId = #{userId}, diagnosisTime = #{diagnosisTime}, diagnosisResult = #{diagnosisResult}, signalStrength = #{signalStrength}, latency = #{latency}, downloadSpeed = #{downloadSpeed}, uploadSpeed = #{uploadSpeed}, diagnosisType = #{diagnosisType}, location = #{location}, deviceModel = #{deviceModel}, networkType = #{networkType}, details = #{details}, updatedAt = #{updatedAt} WHERE id = #{id}")
    int update(Diagnostic diagnostic);

    // 删除诊断记录
    @Delete("DELETE FROM diagnosisRecords WHERE id = #{id}")
    int delete(@Param("id") Integer id);
}